package com.wzdigit.wms.wms.controller.common;

import com.wzdigit.framework.RandomlyThrowsException;
import com.wzdigit.framework.exception.RestStatusException;
import com.wzdigit.framework.model.response.ErrorEntity;
import com.wzdigit.wms.basic.enums.*;
import com.wzdigit.wms.wms.constant.WmsWareConstant;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@Api(tags = "公共枚举控制层")
@RequestMapping(value = WmsWareConstant.API_VERSION)
public class CommonEnumController {
	
    public static final String REQUSET_MODEL = "/sys/common/enum";

    @RandomlyThrowsException
    @ApiOperation(value = "获取货品枚举", notes = "获取货品枚举")
    @ApiResponses({@ApiResponse(code = 500, message = "系统异常", response = ErrorEntity.class)})
    @GetMapping(value = REQUSET_MODEL + "/getSkuEnum")
    public List<Map<String, Object>> getSkuEnum(
            @ApiParam(value = "<条码管控类型:BarcodeControl>"
            		+ "<条码解析方式:BarcodeParser><来源方式:DataSource>"
            		+ "<库位指定方式:ReserveCode><体积重量计算方式:CalculateCode>", required = true) 
            @RequestParam String description,
            HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
        try {
            return SkuEnum.getEnumListByDescription(description);
        } catch (RestStatusException ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }
    
    @RandomlyThrowsException
    @ApiOperation(value = "获取仓库枚举", notes = "获取仓库枚举")
    @ApiResponses({@ApiResponse(code = 500, message = "系统异常", response = ErrorEntity.class)})
    @GetMapping(value = REQUSET_MODEL + "/getWarehouseEnum")
    public List<Map<String, Object>> getWarehouseEnum(
            @ApiParam(value = "<仓库类型:WhsType>", required = true) 
            @RequestParam String description,
            HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
        try {
            return WarehouseEnum.getEnumListByDescription(description);
        } catch (RestStatusException ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }
    
    @RandomlyThrowsException
    @ApiOperation(value = "获取库位枚举", notes = "获取库位枚举")
    @ApiResponses({@ApiResponse(code = 500, message = "系统异常", response = ErrorEntity.class)})
    @GetMapping(value = REQUSET_MODEL + "/getLocationEnum")
    public List<Map<String, Object>> getLocationEnum(
            @ApiParam(value = "<使用方式/用途:LocUsage><库位类型:LocType><属性:LocAttr>"
            			+ "<库位处理:LocHandling><周转需求:Demand>", required = true) 
            @RequestParam String description,
            HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
        try {
            return LocationEnum.getEnumListByDescription(description);
        } catch (RestStatusException ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }
    
    
    @RandomlyThrowsException
    @ApiOperation(value = "获取收货通知单状态枚举", notes = "获取收货通知单状态枚举")
    @ApiResponses({@ApiResponse(code = 500, message = "系统异常", response = ErrorEntity.class)})
    @GetMapping(value = REQUSET_MODEL + "/getAsnHeaderEnum")
    public List<Map<String, Object>> getAsnHeaderEnum(
            @ApiParam(value = "<状态类型:Status>", required = true) 
            @RequestParam String description,
            HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
        try {
            return AsnHeaderStatusEnum.getEnumListByDescription(description);
        } catch (RestStatusException ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }
    
    
    @RandomlyThrowsException
    @ApiOperation(value = "获取收货通知单明细状态枚举", notes = "获取收货通知单明细状态枚举")
    @ApiResponses({@ApiResponse(code = 500, message = "系统异常", response = ErrorEntity.class)})
    @GetMapping(value = REQUSET_MODEL + "/getAsnDtlEnum")
    public List<Map<String, Object>> getAsnDtlEnum(
            @ApiParam(value = "<状态类型:Status>", required = true) 
            @RequestParam String description,
            HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
        try {
            return AsnDtlStatusEnum.getEnumListByDescription(description);
        } catch (RestStatusException ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }
    
    @RandomlyThrowsException
    @ApiOperation(value = "获取收货通知单SN条码状态枚举", notes = "获取收货通知单SN条码状态枚举")
    @ApiResponses({@ApiResponse(code = 500, message = "系统异常", response = ErrorEntity.class)})
    @GetMapping(value = REQUSET_MODEL + "/getAsnDrlSNstatusEnum")
    public List<Map<String, Object>> getAsnDrlSNstatusEnum(
            @ApiParam(value = "<状态类型:Status>", required = true) 
            @RequestParam String description,
            HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
        try {
            return AsnDtlGoodsStatusEnum.getEnumListByDescription(description);
        } catch (RestStatusException ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }
    
    @RandomlyThrowsException
    @ApiOperation(value = "获取调拨通知单类型枚举", notes = "获取调拨通知单类型枚举")
    @ApiResponses({@ApiResponse(code = 500, message = "系统异常", response = ErrorEntity.class)})
    @GetMapping(value = REQUSET_MODEL + "/getTransferTypeEnum")
    public List<Map<String, Object>> getTransferTypeEnum(
            @ApiParam(value = "<调拨通知单类型:TransferType>", required = true) 
            @RequestParam String description,
            HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
        try {
            return TransferTypeEnum.getEnumListByDescription(description);
        } catch (RestStatusException ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }
    
    @RandomlyThrowsException
    @ApiOperation(value = "获取调拨通知单状态枚举", notes = "获取调拨通知单状态枚举")
    @ApiResponses({@ApiResponse(code = 500, message = "系统异常", response = ErrorEntity.class)})
    @GetMapping(value = REQUSET_MODEL + "/getTransferHeaderEnum")
    public List<Map<String, Object>> getTransferHeaderEnum(
            @ApiParam(value = "<状态类型:Status>", required = true) 
            @RequestParam String description,
            HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
        try {
            return TransferHeaderStatusEnum.getEnumListByDescription(description);
        } catch (RestStatusException ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }
    
    @RandomlyThrowsException
    @ApiOperation(value = "获取调拨通知单明细状态枚举", notes = "获取调拨通知单明细状态枚举")
    @ApiResponses({@ApiResponse(code = 500, message = "系统异常", response = ErrorEntity.class)})
    @GetMapping(value = REQUSET_MODEL + "/getTransferHeaderDtlEnum")
    public List<Map<String, Object>> getTransferHeaderDtlEnum(
            @ApiParam(value = "<状态类型:Status>", required = true) 
            @RequestParam String description,
            HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
        try {
            return TransferDtlStatusEnum.getEnumListByDescription(description);
        } catch (RestStatusException ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }
    
    @RandomlyThrowsException
    @ApiOperation(value = "获取调拨通知单SN条码状态枚举", notes = "获取调拨通知单SN条码状态枚举")
    @ApiResponses({@ApiResponse(code = 500, message = "系统异常", response = ErrorEntity.class)})
    @GetMapping(value = REQUSET_MODEL + "/getTransferDtlSNstatusEnum")
    public List<Map<String, Object>> getTransferDtlSNstatusEnum(
            @ApiParam(value = "<状态类型:Status>", required = true) 
            @RequestParam String description,
            HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
        try {
            return TransferDtlGoodStatusEnum.getEnumListByDescription(description);
        } catch (RestStatusException ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }
    
    
    @RandomlyThrowsException
    @ApiOperation(value = "获取货品清单状态枚举", notes = "获取货品清单状态枚举")
    @ApiResponses({@ApiResponse(code = 500, message = "系统异常", response = ErrorEntity.class)})
    @GetMapping(value = REQUSET_MODEL + "/getGoodstatusEnum")
    public List<Map<String, Object>> getGoodstatusEnum(
            @ApiParam(value = "<状态类型:Status>", required = true) 
            @RequestParam String description,
            HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
        try {
            return GoodsStatusEnum.getEnumListByDescription(description);
        } catch (RestStatusException ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }
    
    @RandomlyThrowsException
    @ApiOperation(value = "获取品质状态枚举", notes = "获取品质状态枚举")
    @ApiResponses({@ApiResponse(code = 500, message = "系统异常", response = ErrorEntity.class)})
    @GetMapping(value = REQUSET_MODEL + "/getQaStatusEnum")
    public List<Map<String, Object>> getQaStatusEnum(
            @ApiParam(value = "<品质状态类型:QaStatus>", required = true) 
            @RequestParam String description,
            HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
        try {
            return QaStatusEnum.getEnumListByDescription(description);
        } catch (RestStatusException ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }
    
    @RandomlyThrowsException
    @ApiOperation(value = "获取库存性质枚举", notes = "获取库存性质枚举")
    @ApiResponses({@ApiResponse(code = 500, message = "系统异常", response = ErrorEntity.class)})
    @GetMapping(value = REQUSET_MODEL + "/getInvAttrEnum")
    public List<Map<String, Object>> getInvAttrEnum(
            HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
        try {
            return InvAttrEnum.getEnumListByDescription();
        } catch (RestStatusException ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }


    @ApiOperation(value = "获取拣货任务状态", notes = "获取品质状态枚举")
    @GetMapping(value = REQUSET_MODEL + "/getPicktaskStatusEnum")
    public PicktaskStatusEnum[] getPicktaskStatusEnum(
            HttpServletRequest servletRequest,
            HttpServletResponse servletResponse) {
        try {
            return PicktaskStatusEnum.values();
        } catch (RestStatusException ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }
    
    @ApiOperation(value = "获取车辆型号", notes = "获取车辆型号")
    @GetMapping(value = REQUSET_MODEL + "/getVehicleTypeEnum")
    public Map<Integer, String> getVehicleTypeEnum(
            HttpServletRequest servletRequest,
            HttpServletResponse servletResponse) {
        try {
            return VehicleTypeEnum.getEnumByDescription();
        } catch (RestStatusException ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }
}
